import os

base_dir = "D:/鞠婧祎/微博内容备份-序号在前/"
for _, _, files in os.walk(base_dir):
    # print("files = ", files)
    for file in files:
        file_name = os.path.basename(file)
        name, ex_name = os.path.splitext(file_name)
        if ex_name == '.jpg' or ex_name == '.gif':
            name_list = name.split(' ')
            index = name_list.pop(1)
            name_list.append(index)
            new_name = str(name_list[0]) + ' ' + ''.join(name_list[1:-1]) + ' ' + str(name_list[-1]) + ex_name
            os.rename(base_dir + file, base_dir + new_name)
            print(new_name)